﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using KBC_Quiz_Show.Bussiness;
using System.Collections;
using KBC_Quiz_Show.Object;

namespace KBC_Quiz_Show.Presentation
{
    public partial class FrmChangePass : DevComponents.DotNetBar.Office2007RibbonForm
    {
        AdminController adminController = new AdminController();
        ArrayList userList = new ArrayList();
        public FrmChangePass()
        {
            InitializeComponent();
        }
        public void LoadForm()
        {
            String username = txtUserName.Text;
            userList = adminController.LoadAdminByUser(username);
            foreach (Admin i in userList)
            {
                String pass = i.pass;
                txtCurrentPass.Text = pass;
            }
        }
        public void ChangePass()
        {
            String user = txtUserName.Text;
            String newPassword = txtNewPass.Text;
            String confirmPassword = txtConfirmPass.Text;
            if (newPassword.CompareTo("") != 0 && confirmPassword.CompareTo("") != 0)
            {
                if (newPassword.CompareTo(confirmPassword) == 0)
                {
                    adminController.ChangePass(user, newPassword);
                    MessageBox.Show("Change Password is successful !");
                    this.Visible = false;


                }
                else
                {
                    MessageBox.Show("Please enter confirm password again");
                }
            }
            else
            {
                MessageBox.Show("Password is not empty");
            }
        }
        private void buttonX2_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void FrmChangePass_Load(object sender, EventArgs e)
        {
            this.LoadForm();
            txtUserName.Enabled = false;
            txtCurrentPass.Enabled = false;
        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            this.ChangePass();
        }
    }
}
